#include "ADC_HAL_QG.h"
#include "Digital_Filters.h"

#define mDELAY_TEST_ACCEL 				\
do{   									\
	tempo=10000;						\
	while(--tempo)						\
	{									\
		__RESET_WATCHDOG(); 			\
	}									\
}while(0)

#define SENSOR_ACCEL_X_CH   2
#define SENSOR_ACCEL_Y_CH   3
#define SENSOR_ACCEL_Z_CH   1
#define SENSOR_SLIDER_CH    0
#define SENSOR_BATTERY_CH   7

#define ACCEL_SELF_TEST_DD  PTBDD_PTBDD2
#define ACCEL_SELF_TEST     PTBD_PTBD2

#define ACCEL_NORMAL_OPERATION 0
#define ACCEL_SELF_TEST_MODE   1

#define SENSOR_FREE_FALL_X	1<<0
#define SENSOR_FREE_FALL_Y	1<<1
#define SENSOR_FREE_FALL_Z	1<<2

#define FREE_FALL_MARGIN	10

#define FREE_FALL_MAX		( ADC_10_BIT_ZERO_OFFSET + FREE_FALL_MARGIN )
#define FREE_FALL_MIN		( ADC_10_BIT_ZERO_OFFSET - FREE_FALL_MARGIN )
							  
#define FILTER_ENABLED  1
#define FILTER_DISABLED 0

#define SENSOR_ACCEL_X_FILTER   FILTER_ENABLED
#define SENSOR_ACCEL_Y_FILTER   FILTER_ENABLED
#define SENSOR_ACCEL_Z_FILTER   FILTER_DISABLED
#define SENSOR_SLIDER_FILTER    FILTER_DISABLED
#define SENSOR_BATTERY_FILTER   FILTER_DISABLED
#define SENSOR_LIGHT_FILTER     FILTER_DISABLED

//Considers maximun and minimum sensitivity and self test deflection
//Supuses a 10bit ADC conversion
#define SENSOR_ACCEL_TEST_MAXZ	166
#define SENSOR_ACCEL_TEST_MINZ	102

#define SENSOR_ACCEL_TEST_OK	1
#define SENSOR_ACCEL_TEST_FAIL	0

uint8 u8Sensor_GetAccelX (void);

uint8 u8Sensor_GetAccelY (void);

uint8 u8Sensor_GetAccelZ (void);

//uint8 u8Sensor_GetLightLevel (void);

uint8 u8Sensor_GetBatteryLevel (void);

uint8 u8Sensor_GetSpeed (void);

void vfnSensor_ADC_Config (void);

void vfnSensor_LoadCalibrationValues (void);

uint8 u8Sensor_TestAccel(void);

